import { createStore, combineReducers, applyMiddleware } from 'redux'
// 插件
import thunk from 'redux-thunk'
import logger from 'redux-logger'
// 引入 reducer
import userReducer from './reducer/userReducer'
import listReducer from './reducer/listReducer'
import userHistory from './reducer/userHistory'
// 合拼reduer
const reducer = combineReducers({
	userReducer,
	listReducer,
	userHistory
})

// export type State = type reducer>
// 创建
const store = createStore(reducer, applyMiddleware(thunk, logger))

store.subscribe(() => {
	const state = store.getState();
	const user = state.userReducer.user
	localStorage.setItem('user', JSON.stringify(user))
})


export default store